import axios from 'axios'
import baseURL from './baseURL'

const reuqest = axios.create({
  timeout: 300000,
  baseURL
})

const http: any = {}

http.get = (url: string, options: any) => new Promise((resolve, reject) => {
  reuqest.get(url, options)
    .then((response: any) => {
      if (response.status === 200) {
        resolve(response.data)
      } else {
        reject(response.message)
      }
    }).catch((e) => {
      reject(e.message)
      console.log(e)
    })
})

http.post = (url: string, options: any) => new Promise((resolve, reject) => {
  reuqest.post(url, options)
    .then((response: any) => {
      if (response.status === 200) {
        resolve(response.data)
      } else {
        reject(response.message)
      }
    })
    .catch((e) => {
      console.log(e)
    })
})

export default http
